package com.example.transactionhintassistant.controller;

import com.example.transactionhintassistant.pojo.dto.user.AddUserInfoDto;
import com.example.transactionhintassistant.pojo.dto.user.ChangeUserInfoDto;
import com.example.transactionhintassistant.pojo.vo.UserInfoVo;
import com.example.transactionhintassistant.service.UsersService;
import com.example.transactionhintassistant.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Tag(name = "3.用户模块")
public class UserController {
    @Autowired
    private UsersService usersService;

    @GetMapping("/info")
    @Operation(summary = "获取用户信息", security = {@SecurityRequirement(name = "Authorization")})
    public Result<UserInfoVo> getUserInfo(){
        return usersService.getUserInfo();
    }

    @PostMapping("/info")
    @Operation(summary = "添加用户信息", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> addUserInfo(@RequestBody @Validated AddUserInfoDto addUserInfoDto){
        return usersService.addUserInfo(addUserInfoDto);
    }

    @PutMapping("/info")
    @Operation(summary = "修改用户信息", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> changeUserInfo(@RequestBody @Validated ChangeUserInfoDto changeUserInfoDto){
        return usersService.changeUserInfo(changeUserInfoDto);
    }

    @PutMapping("/colorTheme/{color}")
    @Operation(summary = "修改用户颜色主题", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> changeUserInfo(@PathVariable String color){
        return usersService.changeUserColorTheme(color);
    }

    @DeleteMapping("/info")
    @Operation(summary = "注销用户", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> deleteUser(){
        return usersService.deleteUser();
    }
}
